*------------------------------------------------------------------------------*
*	Paper:			Local Effects of Foreign Direct Investment
*	Authors:		Tobias Rommel, Tabea Palmtag, Luca Messerschmidt
*	Version:		January 29, 2025
*	Data:			FDI projects, nightlights data, V-Dem data
*	Task:			Empirical analysis (Stata, version 17)
*------------------------------------------------------------------------------*


*** Working directory
local dir = "/Users//`=c(username)'/Downloads/RPM_FDIgrowth_Replication"
cd "`dir'"




***** 1. Buffer Analysis
*------------------------------------------------------------------------------*

*** Load data
use "RPM_FDIgrowth_Buffer.dta", clear


*** FIGURE 1: Nightlight intensity, main models
* Unconditional
reghdfe lights_mean_10 cl.lnfdi_capex_cum, absorb(buffer year) cluster(buffer)
regsave L1.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 13, desc, Unconditional, model, buffer) replace
regsave L1.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 13, desc, Unconditional, model, buffer) append
* Democratic regime
reghdfe lights_mean_10 cl.lnfdi_capex_cum#i.democracy, absorb(buffer year) cluster(buffer)
regsave 0b.democracy#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 10, desc, Autocratic regime, model, buffer) append
regsave 0b.democracy#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 10, desc, Autocratic regime, model, buffer) append
regsave 1.democracy#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 9, desc, Democratic regime, model, buffer) append
regsave 1.democracy#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 9, desc, Democratic regime, model, buffer) append
* Vertical accountability
reghdfe lights_mean_10 cl.lnfdi_capex_cum#i.vertacc, absorb(buffer year) cluster(buffer)
regsave 0b.vertacc#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 6, desc, Low accountability, model, buffer) append
regsave 0b.vertacc#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 6, desc, Low accountability, model, buffer) append
regsave 1.vertacc#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 5, desc, High accountability, model, buffer) append
regsave 1.vertacc#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 5, desc, High accountability, model, buffer) append
* Access to justice
reghdfe lights_mean_10 cl.lnfdi_capex_cum#i.accjust, absorb(buffer year) cluster(buffer)
regsave 0b.accjust#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 2, desc, Bad access to justice, model, buffer) append
regsave 0b.accjust#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 2, desc, Bad access to justice, model, buffer) append
regsave 1.accjust#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 1, desc, Good access to justice, model, buffer) append
regsave 1.accjust#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 1, desc, Good access to justice, model, buffer) append


*** TABLE A-1: Nightlight intensity, different FDI measures
* Binary treatment
reghdfe lights_mean_10 l.fdi_treatment, absorb(buffer year) cluster(buffer)
est store growth1
* Cumulative number of FDI projects
reghdfe lights_mean_10 l.fdi_treatment l.lights_mean_10 l.hyde_sum_10, absorb(buffer year) cluster(buffer)
est store growth2
* Sum of FDI, cumulative and logged
reghdfe lights_mean_10 l.lnfdi_capex_cum, absorb(buffer year) cluster(buffer)
est store growth3
* Sum of FDI, cumulative and logged and controls
reghdfe lights_mean_10 l.lnfdi_capex_cum l.lights_mean_10 l.hyde_sum_10, absorb(buffer year) cluster(buffer)
est store growth4
* Sum of jobs created, cumulative and logged
reghdfe lights_mean_10 l.lnfdi_jobs_cum, absorb(buffer year) cluster(buffer)
est store growth5
* Sum of jobs created, cumulative and logged and controls
reghdfe lights_mean_10 l.lnfdi_jobs_cum l.lights_mean_10 l.hyde_sum_10, absorb(buffer year) cluster(buffer)
est store growth6
* Table
esttab growth1 growth2 growth3 growth4 growth5 growth6, ///
	b(3) se(2) starlevels(* 0.10 ** 0.05 *** 0.01) ///
	stats(N N_clust p r2_a, fmt(0 0 3 3) labels("\# of observations" "\# of countries" "Prob > F" "Adj. R-squared")) ///
	order(*fdi* *job*) eqlabels("" "") nogaps 


*** Robustness: Nightlight intensity, without China
reghdfe lights_mean_10 cl.lnfdi_capex_cum if cname!="China", absorb(buffer year) cluster(buffer)
reghdfe lights_mean_10 cl.lnfdi_capex_cum#i.democracy if cname!="China", absorb(buffer year) cluster(buffer)
test 0.democracy#cL.lnfdi_capex_cum = 1.democracy#cL.lnfdi_capex_cum
reghdfe lights_mean_10 cl.lnfdi_capex_cum#i.vertacc if cname!="China", absorb(buffer year) cluster(buffer)
test 0.vertacc#cL.lnfdi_capex_cum = 1.vertacc#cL.lnfdi_capex_cum
reghdfe lights_mean_10 cl.lnfdi_capex_cum#i.accjust if cname!="China", absorb(buffer year) cluster(buffer)
test 0.accjust#cL.lnfdi_capex_cum = 1.accjust#cL.lnfdi_capex_cum


*** FIGURE 2: Nightlight intensity, varying buffer sizes
reghdfe lights_mean_5 cl.lnfdi_capex_cum l.lights_mean_5 l.hyde_sum_5, absorb(buffer year) cluster(buffer)
regsave l.lnfdi_capex_cum using "results_distance.dta", ci level(95) addlabel(km, 5) replace
foreach i of numlist 10 15 20 25 30 35 40 45 50 60 70 80 90 100 {
	reghdfe lights_mean_`i' cl.lnfdi_capex_cum l.lights_mean_`i' l.hyde_sum_`i', absorb(buffer year) cluster(buffer)
	regsave l.lnfdi_capex_cum using "results_distance.dta", ci level(95) addlabel(km, `i') append
}
preserve
use "results_distance", clear
gen n = _n
labmask n, values(km)
twoway 	(scatter n coef, mcolor(gs6) msymbol(O)) ///
		(rcap ci_lower ci_upper n, hori lcolor(gs6) lpattern(solid)), ///
		title("Effect of FDI on Nightlight Intensity") ///
		xtitle("Coefficient in two-way fixed effects OLS model") ///
		ytitle("Buffer zone around FDI project (in km)") ///
		ylabel(1 "100" 2 "90" 3 "80" 4 "70" 5 "60" 6 "50" 7 "45" 8 "40" 9 "35" 10 "30" 11 "25" 12 "20" 13 "15" 14 "10" 15 "5") ///
		xsize(2) ysize(2) legend(off) name(FDIgrowth_buf, replace)
restore


*** Robustness test: Country size
reghdfe lights_mean_5 cl.lnfdi_capex_cum l.lights_mean_5 l.hyde_sum_5 if smallcountry==0, absorb(buffer year) cluster(buffer)
regsave l.lnfdi_capex_cum using "results_distance.dta", ci level(95) addlabel(km, 5) replace
foreach i of numlist 10 15 20 25 30 35 40 45 50 60 70 80 90 100 {
	reghdfe lights_mean_`i' cl.lnfdi_capex_cum l.lights_mean_`i' l.hyde_sum_`i' if smallcountry==0, absorb(buffer year) cluster(buffer)
	regsave l.lnfdi_capex_cum using "results_distance.dta", ci level(95) addlabel(km, `i') append
}
preserve
use "results_distance", clear
gen n = _n
labmask n, values(km)
twoway 	(scatter n coef, mcolor(gs6) msymbol(O)) ///
		(rcap ci_lower ci_upper n, hori lcolor(gs6) lpattern(solid)), ///
		title("Effect of FDI on Nightlight Intensity") ///
		xtitle("Coefficient in two-way fixed effects OLS model") ///
		ytitle("Buffer zone around FDI project (in km)") ///
		ylabel(1 "100" 2 "90" 3 "80" 4 "70" 5 "60" 6 "50" 7 "45" 8 "40" 9 "35" 10 "30" 11 "25" 12 "20" 13 "15" 14 "10" 15 "5") ///
		xsize(2) ysize(2) legend(off) name(FDIgrowth_buf, replace)
restore


*** FIGURE 3: Spatial nightlight inequality, main models
* Unconditional
reghdfe lights_diff_1025 cl.lnfdi_capex_cum, absorb(buffer year) cluster(buffer)
regsave L1.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 13, desc, Unconditional, model, buffer) replace
regsave L1.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 13, desc, Unconditional, model, buffer) append
* Democratic regime
reghdfe lights_diff_1025 cl.lnfdi_capex_cum#i.democracy, absorb(buffer year) cluster(buffer)
regsave 0b.democracy#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 10, desc, Autocratic regime, model, buffer) append
regsave 0b.democracy#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 10, desc, Autocratic regime, model, buffer) append
regsave 1.democracy#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 9, desc, Democratic regime, model, buffer) append
regsave 1.democracy#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 9, desc, Democratic regime, model, buffer) append
* Vertical accountability
reghdfe lights_diff_1025 cl.lnfdi_capex_cum#i.vertacc, absorb(buffer year) cluster(buffer)
regsave 0b.vertacc#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 6, desc, Low accountability, model, buffer) append
regsave 0b.vertacc#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 6, desc, Low accountability, model, buffer) append
regsave 1.vertacc#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 5, desc, High accountability, model, buffer) append
regsave 1.vertacc#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 5, desc, High accountability, model, buffer) append
* Access to justice
reghdfe lights_diff_1025 cl.lnfdi_capex_cum#i.accjust, absorb(buffer year) cluster(buffer)
regsave 0b.accjust#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 2, desc, Bad access to justice, model, buffer) append
regsave 0b.accjust#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 2, desc, Bad access to justice, model, buffer) append
regsave 1.accjust#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 1, desc, Good access to justice, model, buffer) append
regsave 1.accjust#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 1, desc, Good access to justice, model, buffer) append


*** TABLE A-4: Spatial nightlight inequality, different FDI measures
* Binary treatment
reghdfe lights_diff_1025 l.fdi_treatment, absorb(buffer year) cluster(buffer)
est store spatial1
* Cumulative number of FDI projects
reghdfe lights_diff_1025 l.fdi_treatment l.lights_mean_10 l.hyde_sum_10, absorb(buffer year) cluster(buffer)
est store spatial2
* Sum of FDI, cumulative and logged
reghdfe lights_diff_1025 l.lnfdi_capex_cum, absorb(buffer year) cluster(buffer)
est store spatial3
* Sum of FDI, cumulative and logged and controls
reghdfe lights_diff_1025 l.lnfdi_capex_cum l.lights_mean_10 l.hyde_sum_10, absorb(buffer year) cluster(buffer)
est store spatial4
* Sum of jobs created, cumulative and logged
reghdfe lights_diff_1025 l.lnfdi_jobs_cum, absorb(buffer year) cluster(buffer)
est store spatial5
* Sum of jobs created, cumulative and logged and controls
reghdfe lights_diff_1025 l.lnfdi_jobs_cum l.lights_mean_10 l.hyde_sum_10, absorb(buffer year) cluster(buffer)
est store spatial6
* Table
esttab spatial1 spatial2 spatial3 spatial4 spatial5 spatial6, ///
	b(3) se(2) starlevels(* 0.10 ** 0.05 *** 0.01) ///
	stats(N N_clust p r2_a, fmt(0 0 3 3) labels("\# of observations" "\# of countries" "Prob > F" "Adj. R-squared")) ///
	order(*fdi* *job*) eqlabels("" "") nogaps 


*** Robustness: Spatial nightlight inequality, without China
reghdfe lights_diff_1025 cl.lnfdi_capex_cum if cname!="China", absorb(buffer year) cluster(buffer)
reghdfe lights_diff_1025 cl.lnfdi_capex_cum#i.democracy if cname!="China", absorb(buffer year) cluster(buffer)
test 0.democracy#cL.lnfdi_capex_cum = 1.democracy#cL.lnfdi_capex_cum
reghdfe lights_diff_1025 cl.lnfdi_capex_cum#i.vertacc if cname!="China", absorb(buffer year) cluster(buffer)
test 0.vertacc#cL.lnfdi_capex_cum = 1.vertacc#cL.lnfdi_capex_cum
reghdfe lights_diff_1025 cl.lnfdi_capex_cum#i.accjust if cname!="China", absorb(buffer year) cluster(buffer)
test 0.accjust#cL.lnfdi_capex_cum = 1.accjust#cL.lnfdi_capex_cum




***** 2. Grid Analysis
*------------------------------------------------------------------------------*

*** Load data
use "RPM_FDIgrowth_Grid10km.dta", clear


*** FIGURE 1: Nightlight intensity, main models
* Unconditional
reghdfe lights_mean cl.lnfdi_capex_cum, absorb(grid year) cluster(grid)
regsave L1.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 13, desc, Unconditional, model, grid) append
regsave L1.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 13, desc, Unconditional, model, grid) append
* Democratic regime
reghdfe lights_mean cl.lnfdi_capex_cum#i.democracy, absorb(grid year) cluster(grid)
regsave 0b.democracy#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 10, desc, Autocratic regime, model, grid) append
regsave 0b.democracy#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 10, desc, Autocratic regime, model, grid) append
regsave 1.democracy#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 9, desc, Democratic regime, model, grid) append
regsave 1.democracy#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 9, desc, Democratic regime, model, grid) append
* Vertical accountability
reghdfe lights_mean cl.lnfdi_capex_cum#i.vertacc, absorb(grid year) cluster(grid)
regsave 0b.vertacc#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 6, desc, Low accountability, model, grid) append
regsave 0b.vertacc#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 6, desc, Low accountability, model, grid) append
regsave 1.vertacc#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 5, desc, High accountability, model, grid) append
regsave 1.vertacc#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 5, desc, High accountability, model, grid) append
* Access to justice
reghdfe lights_mean cl.lnfdi_capex_cum#i.accjust, absorb(grid year) cluster(grid)
regsave 0b.accjust#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 2, desc, Bad access to justice, model, grid) append
regsave 0b.accjust#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 2, desc, Bad access to justice, model, grid) append
regsave 1.accjust#cL.lnfdi_capex_cum using "results_growth.dta", ci level(95) addlabel(n, 1, desc, Good access to justice, model, grid) append
regsave 1.accjust#cL.lnfdi_capex_cum using "results_growth.dta", ci level(83) addlabel(n, 1, desc, Good access to justice, model, grid) append


*** TABLE A-2: Nightlight intensity, different FDI measures
* Binary treatment
reghdfe lights_mean l.fdi_treatment, absorb(grid year) cluster(grid)
est store growth1
* Cumulative number of FDI projects
reghdfe lights_mean l.fdi_treatment l.lights_mean l.hyde_sum, absorb(grid year) cluster(grid)
est store growth2
* Sum of FDI, cumulative and logged
reghdfe lights_mean l.lnfdi_capex_cum, absorb(grid year) cluster(grid)
est store growth3
* Sum of FDI, cumulative and logged and controls
reghdfe lights_mean l.lnfdi_capex_cum l.lights_mean l.hyde_sum, absorb(grid year) cluster(grid)
est store growth4
* Sum of jobs created, cumulative and logged
reghdfe lights_mean l.lnfdi_jobs_cum, absorb(grid year) cluster(grid)
est store growth5
* Sum of jobs created, cumulative and logged and lcontrols
reghdfe lights_mean l.lnfdi_jobs_cum l.lights_mean l.hyde_sum, absorb(grid year) cluster(grid)
est store growth6
* Table
esttab growth1 growth2 growth3 growth4 growth5 growth6, ///
	b(3) se(2) starlevels(* 0.10 ** 0.05 *** 0.01) ///
	stats(N N_clust p r2_a, fmt(0 0 3 3) labels("\# of observations" "\# of countries" "Prob > F" "Adj. R-squared")) ///
	order(*fdi* *job*) eqlabels("" "") nogaps 


*** TABLE A-3: Nightlight intensity, only treated grids and neighbors
* Binary treatment
reghdfe lights_mean l.fdi_treatment if neighbor==1, absorb(grid year) cluster(grid)
est store growth11
* Cumulative number of FDI projects
reghdfe lights_mean l.fdi_treatment l.lights_mean l.hyde_sum if neighbor==1, absorb(grid year) cluster(grid)
est store growth12
* Sum of FDI, cumulative and logged
reghdfe lights_mean l.lnfdi_capex_cum if neighbor==1, absorb(grid year) cluster(grid)
est store growth13
* Sum of FDI, cumulative and logged and controls
reghdfe lights_mean l.lnfdi_capex_cum l.lights_mean l.hyde_sum if neighbor==1, absorb(grid year) cluster(grid)
est store growth14
* Sum of jobs created, cumulative and logged
reghdfe lights_mean l.lnfdi_jobs_cum if neighbor==1, absorb(grid year) cluster(grid)
est store growth15
* Sum of jobs created, cumulative and logged and lcontrols
reghdfe lights_mean l.lnfdi_jobs_cum l.lights_mean l.hyde_sum if neighbor==1, absorb(grid year) cluster(grid)
est store growth16
* Table
esttab growth11 growth12 growth13 growth14 growth15 growth16, ///
	b(3) se(2) starlevels(* 0.10 ** 0.05 *** 0.01) ///
	stats(N N_clust p r2_a, fmt(0 0 3 3) labels("\# of observations" "\# of countries" "Prob > F" "Adj. R-squared")) ///
	order(*fdi* *job*) eqlabels("" "") nogaps 


*** Robustness: Nightlight intensity, without China
reghdfe lights_mean cl.lnfdi_capex_cum if cname!="China", absorb(grid year) cluster(grid)
reghdfe lights_mean cl.lnfdi_capex_cum#i.democracy if cname!="China", absorb(grid year) cluster(grid)
test 0.democracy#cL.lnfdi_capex_cum = 1.democracy#cL.lnfdi_capex_cum
reghdfe lights_mean cl.lnfdi_capex_cum#i.vertacc if cname!="China", absorb(grid year) cluster(grid)
test 0.vertacc#cL.lnfdi_capex_cum = 1.vertacc#cL.lnfdi_capex_cum
reghdfe lights_mean cl.lnfdi_capex_cum#i.accjust if cname!="China", absorb(grid year) cluster(grid)
test 0.accjust#cL.lnfdi_capex_cum = 1.accjust#cL.lnfdi_capex_cum


*** Robustness: Nightlight intensity, without highly populated areas
reghdfe lights_mean cl.lnfdi_capex_cum if lowpop==1, absorb(grid year) cluster(grid)
reghdfe lights_mean cl.lnfdi_capex_cum#i.democracy if lowpop==1, absorb(grid year) cluster(grid)
test 0.democracy#cL.lnfdi_capex_cum = 1.democracy#cL.lnfdi_capex_cum
reghdfe lights_mean cl.lnfdi_capex_cum#i.vertacc if lowpop==1, absorb(grid year) cluster(grid)
test 0.vertacc#cL.lnfdi_capex_cum = 1.vertacc#cL.lnfdi_capex_cum
reghdfe lights_mean cl.lnfdi_capex_cum#i.accjust if lowpop==1, absorb(grid year) cluster(grid)
test 0.accjust#cL.lnfdi_capex_cum = 1.accjust#cL.lnfdi_capex_cum


*** FIGURE 3: Spatial nightlight inequality, main models
* Unconditional
reghdfe lights_diff cl.lnfdi_capex_cum, absorb(grid year) cluster(grid)
regsave L1.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 13, desc, Unconditional, model, grid) append
regsave L1.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 13, desc, Unconditional, model, grid) append
* Democratic regime
reghdfe lights_diff cl.lnfdi_capex_cum#i.democracy, absorb(grid year) cluster(grid)
regsave 0b.democracy#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 10, desc, Autocratic regime, model, grid) append
regsave 0b.democracy#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 10, desc, Autocratic regime, model, grid) append
regsave 1.democracy#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 9, desc, Democratic regime, model, grid) append
regsave 1.democracy#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 9, desc, Democratic regime, model, grid) append
* Vertical accountability
reghdfe lights_diff cl.lnfdi_capex_cum#i.vertacc, absorb(grid year) cluster(grid)
regsave 0b.vertacc#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 6, desc, Low accountability, model, grid) append
regsave 0b.vertacc#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 6, desc, Low accountability, model, grid) append
regsave 1.vertacc#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 5, desc, High accountability, model, grid) append
regsave 1.vertacc#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 5, desc, High accountability, model, grid) append
* Access to justice
reghdfe lights_diff cl.lnfdi_capex_cum#i.accjust, absorb(grid year) cluster(grid)
regsave 0b.accjust#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 2, desc, Bad access to justice, model, grid) append
regsave 0b.accjust#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 2, desc, Bad access to justice, model, grid) append
regsave 1.accjust#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(95) addlabel(n, 1, desc, Good access to justice, model, grid) append
regsave 1.accjust#cL.lnfdi_capex_cum using "results_spatial.dta", ci level(83) addlabel(n, 1, desc, Good access to justice, model, grid) append


*** TABLE A-5: Spatial nightlight inequality, different FDI measures
* Binary treatment
reghdfe lights_diff l.fdi_treatment, absorb(grid year) cluster(grid)
est store spatial1
* Cumulative number of FDI projects
reghdfe lights_diff l.fdi_treatment l.lights_mean l.hyde_sum, absorb(grid year) cluster(grid)
est store spatial2
* Sum of FDI, cumulative and logged
reghdfe lights_diff l.lnfdi_capex_cum, absorb(grid year) cluster(grid)
est store spatial3
* Sum of FDI, cumulative and logged and controls
reghdfe lights_diff l.lnfdi_capex_cum l.lights_mean l.hyde_sum, absorb(grid year) cluster(grid)
est store spatial4
* Sum of jobs created, cumulative and logged
reghdfe lights_diff l.lnfdi_jobs_cum, absorb(grid year) cluster(grid)
est store spatial5
* Sum of jobs created, cumulative and logged and controls
reghdfe lights_diff l.lnfdi_jobs_cum l.lights_mean l.hyde_sum, absorb(grid year) cluster(grid)
est store spatial6
* Table
esttab spatial1 spatial2 spatial3 spatial4 spatial5 spatial6, ///
	b(3) se(2) starlevels(* 0.10 ** 0.05 *** 0.01) ///
	stats(N N_clust p r2_a, fmt(0 0 3 3) labels("\# of observations" "\# of countries" "Prob > F" "Adj. R-squared")) ///
	order(*fdi* *job*) eqlabels("" "") nogaps 


*** TABLE A-6: Spatial nightlight inequality, only treated grids and neighbors
* Binary treatment
reghdfe lights_diff l.fdi_treatment if neighbor==1, absorb(grid year) cluster(grid)
est store spatial11
* Cumulative number of FDI projects
reghdfe lights_diff l.fdi_treatment l.lights_mean l.hyde_sum if neighbor==1, absorb(grid year) cluster(grid)
est store spatial12
* Sum of FDI, cumulative and logged
reghdfe lights_diff l.lnfdi_capex_cum if neighbor==1, absorb(grid year) cluster(grid)
est store spatial13
* Sum of FDI, cumulative and logged and controls
reghdfe lights_diff l.lnfdi_capex_cum l.lights_mean l.hyde_sum if neighbor==1, absorb(grid year) cluster(grid)
est store spatial14
* Sum of jobs created, cumulative and logged
reghdfe lights_diff l.lnfdi_jobs_cum if neighbor==1, absorb(grid year) cluster(grid)
est store spatial15
* Sum of jobs created, cumulative and logged and controls
reghdfe lights_diff l.lnfdi_jobs_cum l.lights_mean l.hyde_sum if neighbor==1, absorb(grid year) cluster(grid)
est store spatial16
* Table
esttab spatial11 spatial12 spatial13 spatial14 spatial15 spatial16, ///
	b(3) se(2) starlevels(* 0.10 ** 0.05 *** 0.01) ///
	stats(N N_clust p r2_a, fmt(0 0 3 3) labels("\# of observations" "\# of countries" "Prob > F" "Adj. R-squared")) ///
	order(*fdi* *job*) eqlabels("" "") nogaps 


*** Robustness: Nightlight intensity, without China
reghdfe lights_diff cl.lnfdi_capex_cum if cname!="China", absorb(grid year) cluster(grid)
reghdfe lights_diff cl.lnfdi_capex_cum#i.democracy if cname!="China", absorb(grid year) cluster(grid)
test 0.democracy#cL.lnfdi_capex_cum = 1.democracy#cL.lnfdi_capex_cum
reghdfe lights_diff cl.lnfdi_capex_cum#i.vertacc if cname!="China", absorb(grid year) cluster(grid)
test 0.vertacc#cL.lnfdi_capex_cum = 1.vertacc#cL.lnfdi_capex_cum
reghdfe lights_diff cl.lnfdi_capex_cum#i.accjust if cname!="China", absorb(grid year) cluster(grid)
test 0.accjust#cL.lnfdi_capex_cum = 1.accjust#cL.lnfdi_capex_cum


*** Robustness: Nightlight intensity, without highly populated areas
reghdfe lights_diff cl.lnfdi_capex_cum if lowpop==1, absorb(grid year) cluster(grid)
reghdfe lights_diff cl.lnfdi_capex_cum#i.democracy if lowpop==1, absorb(grid year) cluster(grid)
test 0.democracy#cL.lnfdi_capex_cum = 1.democracy#cL.lnfdi_capex_cum
reghdfe lights_diff cl.lnfdi_capex_cum#i.vertacc if lowpop==1, absorb(grid year) cluster(grid)
test 0.vertacc#cL.lnfdi_capex_cum = 1.vertacc#cL.lnfdi_capex_cum
reghdfe lights_diff cl.lnfdi_capex_cum#i.accjust if lowpop==1, absorb(grid year) cluster(grid)
test 0.accjust#cL.lnfdi_capex_cum = 1.accjust#cL.lnfdi_capex_cum


*** Load data
use "RPM_FDIgrowth_Grid25km.dta", clear


*** Robustness: Nightlight intensity, larger grid cells
reghdfe lights_mean cl.lnfdi_capex_cum, absorb(grid year) cluster(grid)
reghdfe lights_mean cl.lnfdi_capex_cum#i.democracy, absorb(grid year) cluster(grid)
test 0.democracy#cL.lnfdi_capex_cum = 1.democracy#cL.lnfdi_capex_cum
reghdfe lights_mean cl.lnfdi_capex_cum#i.vertacc, absorb(grid year) cluster(grid)
test 0.vertacc#cL.lnfdi_capex_cum = 1.vertacc#cL.lnfdi_capex_cum
reghdfe lights_mean cl.lnfdi_capex_cum#i.accjust, absorb(grid year) cluster(grid)
test 0.accjust#cL.lnfdi_capex_cum = 1.accjust#cL.lnfdi_capex_cum


*** Robustness: Spatial nightlight inequality, larger grid cells
reghdfe lights_diff cl.lnfdi_capex_cum, absorb(grid year) cluster(grid)
reghdfe lights_diff cl.lnfdi_capex_cum#i.democracy, absorb(grid year) cluster(grid)
test 0.democracy#cL.lnfdi_capex_cum = 1.democracy#cL.lnfdi_capex_cum
reghdfe lights_diff cl.lnfdi_capex_cum#i.vertacc, absorb(grid year) cluster(grid)
test 0.vertacc#cL.lnfdi_capex_cum = 1.vertacc#cL.lnfdi_capex_cum
reghdfe lights_diff cl.lnfdi_capex_cum#i.accjust, absorb(grid year) cluster(grid)
test 0.accjust#cL.lnfdi_capex_cum = 1.accjust#cL.lnfdi_capex_cum




***** 3. Figures
*------------------------------------------------------------------------------*

*** FIGURE 1: Nightlight intensity
preserve
use "results_growth", clear
sort n
labmask n, values(desc)
twoway 	(scatter n coef if model=="buffer", mcolor(gs6) msymbol(O)) ///
		(rcap ci_lower ci_upper n if model=="buffer", hori lcolor(gs6) lpattern(solid) msize(vsmall)), ///
		ytitle("") title("buffer approach") ///
		ylabel(1 2 5 6 9 10 13, valuelabels nogrid) ///
		yline(3.5 7.5 11.5, lpattern(dot) lcolor(gs10)) ///
		fxsize(60) fysize(100) legend(off) name(FDIgrowth_buffer, replace)
twoway 	(scatter n coef if model=="grid", mcolor(gs6) msymbol(O)) ///
		(rcap ci_lower ci_upper n if model=="grid", hori lcolor(gs6) lpattern(solid) msize(vsmall)), ///
		ytitle("") title("grid approach") ///
		ylabel(1 2 5 6 9 10 13, nolabel nogrid) ///
		yline(3.5 7.5 11.5, lpattern(dot) lcolor(gs10)) ///
		fxsize(40) fysize(100) legend(off) name(FDIgrowth_grid, replace)
graph combine FDIgrowth_buffer FDIgrowth_grid, ycommon col(2) ///
	title("Effect of FDI Project Flows on Nightlight Intensity") ///
	b1title("Coefficient in two-way fixed effects OLS model", size(*.8)) ///
	xsize(3) ysize(2.5) name(FDIgrowth, replace)
restore


*** FIGURE 3: Spatial nightlight inequality
use "results_spatial", clear
sort n
labmask n, values(desc)
twoway 	(scatter n coef if model=="buffer", mcolor(gs6) msymbol(O)) ///
		(rcap ci_lower ci_upper n if model=="buffer", hori lcolor(gs6) lpattern(solid) msize(vsmall)), ///
		ytitle("") title("buffer approach") ///
		ylabel(1 2 5 6 9 10 13, valuelabels nogrid) ///
		yline(3.5 7.5 11.5, lpattern(dot) lcolor(gs10)) ///
		fxsize(60) fysize(100) legend(off) name(FDIspatial_buffer, replace)
twoway 	(scatter n coef if model=="grid", mcolor(gs6) msymbol(O)) ///
		(rcap ci_lower ci_upper n if model=="grid", hori lcolor(gs6) lpattern(solid) msize(vsmall)), ///
		ytitle("") title("grid approach") ///
		ylabel(1 2 5 6 9 10 13, nolabel nogrid) ///
		yline(3.5 7.5 11.5, lpattern(dot) lcolor(gs10)) ///
		fxsize(40) fysize(100) legend(off) name(FDIspatial_grid, replace)
graph combine FDIspatial_buffer FDIspatial_grid, ycommon col(2) ///
	title("Effect of FDI Project Flows on Spatial Nightlight Inequality") ///
	b1title("Coefficient in two-way fixed effects OLS model", size(*.8)) ///
	xsize(3) ysize(2.5) name(FDIspatial, replace)

erase "results_distance.dta"
erase "results_growth.dta"
erase "results_spatial.dta"




*------------------------------------------------------------------------------*


capture log close
exit
